package com.masterclient.app.modules.income;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.eoner.baselibrary.widget.EnhanceTabLayout;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.BaseActivity;
import com.masterclient.app.R;
import com.masterclient.app.modules.coupon.adapter.CouponPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：sean
 * 创建时间：2017/8/4 10:43
 * 功能说明：
 */
@Route(path = AroutePath.UNFREEZE_ACTIVITY)
public class UnfreezeActivity extends BaseActivity {

    @BindView(R.id.view_head)
    View viewHead;
    @BindView(R.id.tabLayout)
    EnhanceTabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.tv_total_income)
    TextView tvTotalIncome;
    @BindView(R.id.tv_total_expenses)
    TextView tvTotalExpenses;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_income_and_expend);
        ButterKnife.bind(this);

        tvTitle.setText("冻结/解冻");
        tvTotalIncome.setVisibility(View.GONE);
        List<Fragment> list = new ArrayList<>();
        UnfreezeListFragment unfreezeListFragment1 = UnfreezeListFragment.newInstance("0");
        unfreezeListFragment1.setOnRefreshSuccessListener(frozenTotalTitle -> {
            if (!TextUtils.isEmpty(frozenTotalTitle)){
                viewHead.setVisibility(View.VISIBLE);
                tvTotalExpenses.setText(frozenTotalTitle);
            }else {
                viewHead.setVisibility(View.GONE);
            }
        });
        list.add(unfreezeListFragment1);
        UnfreezeListFragment unfreezeListFragment3 = UnfreezeListFragment.newInstance("3");
        unfreezeListFragment3.setOnRefreshSuccessListener(frozenTotalTitle -> {
            if (!TextUtils.isEmpty(frozenTotalTitle)){
                viewHead.setVisibility(View.VISIBLE);
                tvTotalExpenses.setText(frozenTotalTitle);
            }else {
                viewHead.setVisibility(View.GONE);
            }
        });
        list.add(unfreezeListFragment3);
        UnfreezeListFragment unfreezeListFragment4 = UnfreezeListFragment.newInstance("4");
        unfreezeListFragment4.setOnRefreshSuccessListener(frozenTotalTitle -> {
            if (!TextUtils.isEmpty(frozenTotalTitle)){
                viewHead.setVisibility(View.VISIBLE);
                tvTotalExpenses.setText(frozenTotalTitle);
            }else {
                viewHead.setVisibility(View.GONE);
            }
        });
        list.add(unfreezeListFragment4);


        String [] sTitle = {"全部","冻结","解冻"};
        CouponPagerAdapter pagerAdapter = new CouponPagerAdapter(getSupportFragmentManager(), list, sTitle);
        for(int i=0;i<sTitle.length;i++){
            tabLayout.addTab(sTitle[i],i == 0);
        }
        viewPager.setAdapter(pagerAdapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout.getTabLayout()));
        tabLayout.setupWithViewPager(viewPager);
    }

    @OnClick({R.id.rl_back}) void onClick(View view){
        if (view.getId() == R.id.rl_back) {
            finish();
        }
    }
}
